import axios from "axios";
import {Message} from "element-ui"
import router from "../router"
axios.defaults.baseURL = 'http://124.223.220.96:28019/manage-api/v1';//请求地址

// axios.defaults.headers.delete['Content-Type'] = 'application/x-www-form-urlencoded';
axios.interceptors.request.use((config) => {

    if(config.url!="/adminUser/login"){//处理登录页面 其他所有页面我都加token

        config.headers.token=sessionStorage.getItem("token");
    }
    return config;
}, (error) => {
    return Promise.reject(error);
});



axios.interceptors.response.use((response) => {//响应拦截
// console.log(response.data.resultCode);
if(response.data.resultCode==419){//未登录
    // Message();
    Message({
        message: response.data.message,
        type: 'warning',
        duration:2000
    })

    router.replace("/")//跳转地址
}else{
    Message({
        message: "请求成功",
        type: 'success',
        duration:2000
    })
}




    return response.data;
}, (error) => {
    return Promise.reject(error);
});
export default axios;